home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 March: Reference Library / Dev.CD Mar 97 RL.toast / mac / Technical Documentation / Macintosh Technical Notes / technotes / tn / 1076_MsgTest.hqx / MsgTest / MacMsgTest / Messaging.h < prev    next >
Encoding:
Text File  |  1996-08-29  |  4.6 KB  |  142 lines

  1. // •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. // Messages.h
  3. // 
  4. // July 31, 1996
  5. // By Ben Manuto
  6. // 
  7. // © 1996 by Apple Computer, Inc., all rights reserved.
  8. // 
  9. // This file contains constants and specially defined paramblocks for use with the
  10. // messaging system as well as the Universal procedure definitions for PPC programming.
  11. //
  12. // •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  13.  
  14.  
  15. #ifndef __TYPES__
  16. #include <Types.h>
  17. #endif
  18.  
  19.  
  20.  
  21. #define    kDriverName        "\p.Symbiosis"            // The name of the driver
  22.  
  23.  
  24. // •••••••••• ParamBlockRec for .Symbiosis driver.
  25.  
  26. typedef    struct {
  27.     QElemPtr         qLink;                        // queue link in header
  28.     SInt16             qType;                        // type byte for safety check
  29.     SInt16             ioTrap;                        // not used for messaging.
  30.     Ptr             ioCmdAddr;                    // not used for messaging.
  31.     ProcPtr         ioCompletion;                // completion routine addr (0 for synch calls)
  32.     OSErr             ioResult;                    // result code
  33.     StringPtr         ioNamePtr;                    // not used for messaging.
  34.     SInt16             ioVRefNum;                    // not used for messaging.
  35.     SInt16             ioCRefNum;                     // refNum for I/O operation
  36.     SInt16            csCode;                        // The operation code
  37.     void *            csPtr;                        // pointer to procedure or data
  38.     SInt32            csData;                        // data
  39.     SInt32            csData2;                    // data
  40. } SBParamBlockRec, *SBParamBlockRecPtr;            // 'SB' for 'S'ym'B'iosis
  41.  
  42.  
  43. // •••••••••• Message Universal Procedure Pointers
  44.  
  45. #if GENERATINGCFM
  46. typedef UniversalProcPtr MsgCompletionUPP;
  47. typedef UniversalProcPtr MsgReceiveUPP;
  48. #else
  49. typedef ProcPtr             MsgCompletionUPP;
  50. typedef ProcPtr             MsgReceiveUPP;
  51. #endif
  52.  
  53.  
  54. // •••••••••• Message control codes
  55.  
  56. enum    {
  57.     eSendMessage            = 800,            // Send a message
  58.     eInstallMsgHandler        = 801,            // Install a message handler
  59.     eRemoveMsgHandler        = 802,            // Remove message handler
  60.     eRegisterMessage        = 803            // Register message type
  61. };
  62.  
  63.  
  64. // •••••••••• Message Results (in msgResult field of MsgPBlk)
  65.  
  66. enum {
  67.     msgNoError        = 0,                    // No error, completed
  68.     msgOverrun        = -1,                    // More data was available
  69.     msgUnderrun        = -2,                    // Less data was available
  70.     msgTimeout        = -3                    // Timeout error
  71. };
  72.  
  73.  
  74. // •••••••••• Message Parameter block.
  75.  
  76. typedef struct MsgPBlk {
  77.     struct MsgPBlk*        msgQLink;            // Pointer to next queue element
  78.     SInt16                msgQType;            // Queue Flags
  79.     SInt16                msgCmd;                // The message type or command
  80.     SInt32                msgParam1;            // Message parameter 1
  81.     SInt32                msgParam2;            // Message parameter 2
  82.     void*                msgBuffer;            // Ptr to the message data buffer
  83.     SInt32                msgReqCount;        // Requested data length
  84.     SInt32                msgActCount;        // Actual data length
  85.     MsgCompletionUPP    msgCompletion;        // Ptr to completion routine or NULL
  86.     SInt16                msgResult;            // The result of message operation
  87.     UInt16                msgFlags;            // Message flags (swap and shared)
  88.     UInt32                msgUserData;        // For use by caller (a5, etc…)
  89. } MsgPBlk, *MsgPBlkPtr;
  90.  
  91.  
  92. // •••••••••• Message Record Element.
  93.  
  94. typedef struct MsgRecElem {
  95.     struct MsgRecElem*    recQLink;            // Next queue element
  96.     SInt16                recQType;            // queue flags
  97.     SInt16                recFlags;            // Not used...Set to zero
  98.     MsgReceiveUPP        recProc;            // Ptr to the receive procedure
  99.     SInt16                recCmdBase;            // first command received by this proc
  100.     SInt16                recCmdCount;        // # of commands allocated for this proc
  101.     UInt32                recUserData;        // For caller's use (could be A5...)
  102. } MsgRecElem, *MsgRecElemPtr;
  103.                 
  104.  
  105. // •••••••••• Message Universal Procedure Information 
  106.  
  107. enum {
  108.     uppMsgReceiveProcInfo = kRegisterBased
  109.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(MsgRecElemPtr)))
  110.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(SInt16)))
  111.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterD1, SIZE_CODE(sizeof(SInt32)))
  112.          | REGISTER_ROUTINE_PARAMETER(4, kRegisterD2, SIZE_CODE(sizeof(SInt32)))
  113.          | REGISTER_RESULT_LOCATION(kRegisterA0)
  114.          | RESULT_SIZE(kFourByteCode),
  115.          
  116.     uppMsgCompletionProcInfo = kRegisterBased
  117.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA0, SIZE_CODE(sizeof(MsgPBlkPtr)))
  118.          | REGISTER_RESULT_LOCATION(kRegisterA0)
  119.          | RESULT_SIZE(kFourByteCode)
  120. };
  121.  
  122.  
  123. // •••••••••• Message Universal Procedure Pointer Creation Macros
  124.  
  125. #if GENERATINGCFM
  126. #define NewMsgReceiveProc(userRoutine) \
  127.         (MsgReceiveUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMsgReceiveProcInfo, GetCurrentArchitecture())
  128. #else
  129. #define NewMsgReceiveProc(userRoutine) \
  130.         ((MsgReceiveUPP) (userRoutine))
  131. #endif
  132.  
  133. #if GENERATINGCFM
  134. #define NewMsgCompletionProc(userRoutine) \
  135.         (MsgCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMsgCompletionProcInfo, GetCurrentArchitecture())
  136. #else
  137. #define NewMsgCompletionProc(userRoutine) \
  138.         ((MsgCompletionUPP) (userRoutine))
  139. #endif
  140.  
  141.  
  142.